home *** CD-ROM | disk | FTP | other *** search
- /*
-
- LJ -- A printing utility for the HP LaserJet
-
- This program prints a series of files on the LaserJet printer. The
- files are printed in a "landscape" font at 17 characters to the inch.
- To take advantage of this density, two "pages" of information from
- the file are printed on each piece of paper (left and right halves).
-
- Usage is: LJ file1 file2 file3 ...
-
- Where file# is a valid MS-DOS filename, included on the command line.
-
- April 28, 1985 Joe Barnhart
- May 22, 1985 revised by RGD for page #s, date, time
-
- compiles with Lattice C version 2.15
-
- */
-
- #include <h\stdio.h>
-
- #define MAXLINE 56
- #define PAGE '\014'
-
- struct /* 8086 registers */
- { int ax,bx,cx,dx,si,di;
- } regs;
-
- main(argc, argv)
- int argc;
- char *argv[];
-
- { int filenum;
- FILE *fp,*prn;
-
- prn = fopen("PRN:","w");
- if (prn == NULL)
- printf("%s","Error opening printer as file.\n");
- else
- /* initialize the LaserJet for landscape printing */
- fprintf(prn,"%s","\033E\033&l1O\033(s17H\033&l8d6e57F");
- for (filenum = 1;filenum < argc;filenum++)
- { fp = fopen(argv[filenum],"r");
- if (fp == NULL)
- printf("%s %s %s\n","File:",argv[filenum],"doesn't exist");
- else
- { printf("%s %s\n","Now printing",argv[filenum]);
- printfile(fp,prn,argv[filenum]);
- fclose(fp);
- }
- }
- fprintf(prn,"%s","\015\033E"); /* clear LaserJet */
- }
-
- printfile(fp,prn,filename)
- FILE *fp,*prn;
- char *filename;
- {
- int pagenum = 0;
-
- while(!feof(fp))
- { fprintf(prn,"%s","\033&a85m5L\015"); /* select left half */
- pagenum++;
- printpage(fp,prn,filename,pagenum); /* print one page */
- if (!feof(fp)) /* if more to print... */
- { fprintf(prn,"%s","\033&a0R"); /* move to top of page */
- fprintf(prn,"%s","\033&a171m91L"); /* select right half */
- pagenum++;
- printpage(fp,prn,filename,pagenum); /* and print another page */
- }
- fputc(PAGE,prn); /* kick out paper */
- }
- }
-
- printpage(fp,prn,filename,pagenum)
- FILE *fp,*prn;
- char *filename;
- int pagenum;
-
- { char c,date[20],time[20];
- int line,col,i,tablen;
-
- line = 2;
- col = 0;
- sdatef(date); /* format date string */
- stimef(time); /* format time string */
- fprintf(prn,"File: %-40s",filename); /* print page header */
- fprintf(prn,"Page %d %s %s",pagenum,date,time);
- fputc('\n',prn); /* two blank lines */
- fputc('\n',prn);
- while(line < MAXLINE && (c = fgetc(fp)) != PAGE)
- switch(c)
- { case '\n': /* newline found */
- col = 0; /* zero column and */
- line++; /* advance line count */
- fputc('\n',prn);
- break;
- case '\t': /* TAB found */
- tablen = 8 - col % 8; /* calculate spaces */
- for(i = 1; i <= tablen; i++) /* and print them */
- fputc('\040',prn);
- col += tablen;
- break;
- case '\xFF': /* EOF found */
- line = MAXLINE; /* force termination of loop */
- break;
- default: /* no special case */
- fputc(c,prn); /* print character */
- col++;
- break;
- }
- }
-
-
- getdate(year,month,day)
- int *year,*month,*day;
-
- { regs.ax = 0x2a00; /* read system date */
- int86(0x21,®s,®s);
- *month = ( regs.dx >> 8 ) & 255;
- *day = regs.dx & 255;
- *year = regs.cx;
- }
-
-
- gettime(hours,minutes,seconds)
- int *hours,*minutes,*seconds;
-
- { regs.ax = 0x2c00; /* read system time */
- int86(0x21,®s,®s);
- *hours = ( regs.cx >> 8 ) & 255;
- *minutes = regs.cx & 255;
- *seconds = ( regs.dx >> 8 ) & 255;
- }
-
-
- sdatef(datestring) /* format current */
- char *datestring; /* date into ASCII */
-
- { int year,month,day;
- getdate(&year,&month,&day);
- sprintf(datestring,"%02d/%02d/%02d",month,day,year-1900);
- }
-
-
- stimef(timestring) /* format current */
- char *timestring; /* time into ASCII */
-
- { int hours,minutes,seconds;
- gettime(&hours,&minutes,&seconds);
- sprintf(timestring,"%02d:%02d",hours,minutes);
- }